﻿@model TestAppSite.Models.UploadFileViewModel
@{
    ViewBag.Title = "Index";
}
<style>
    td {
        vertical-align: top;
    }

    .value {
        margin: 5px 0;
    }

    div.value {
        padding: 5px;
        background-color: white;
    }

    .label {
        padding-top: 10px;
        vertical-align: top;
        text-wrap: avoid;
        font-weight: bold;
    }

    input[type=file] {
        height: 2em;
        width: 100%;
    }

    pre {
        overflow: hidden;
    }

    img {
        width: 40%;
    }
</style>

<h2>Index</h2>
@using (Html.BeginForm("Index", "Uploads", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file">
    <input type="submit" name="Submit" id="Submit" value="Upload" />
}

@if (Model != null)
{
    <h3>File uploaded successfully!</h3>
    <table>
        <tr>
            <td class="label">Filename</td>
            <td><div class="value">@Model.Filename</div></td>
        </tr>
        <tr>
            <td class="label">Content Type</td>
            <td><div class="value">@Model.ContentType</div></td>
        </tr>
        <tr>
            <td class="label">Hash</td>
            <td><div class="value">@Model.MD5</div></td>
        </tr>
        @if (Model.ContentType.StartsWith("text/") || Model.ContentType == "application/xml")
        {
        <tr>
            <td class="label">Content</td>
            <td><div class="value"><pre>@Html.Raw(Model.AsText().Replace(Environment.NewLine, "<br />"))</pre></div></td>
        </tr>
        }
        else if (Model.ContentType.StartsWith("image/"))
        {
            <tr>
                <td class="label">Content</td>
                <td><img src="@Model.AsDataUri()" /></td>
            </tr>
        }
    </table>
}